package com.sgx.learning.luban.jvm;

import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Long[] temp = new Long[]{3L,30L,34L,5L,9L};
        long back = lager(temp);
        System.out.println(back);
    }
    public static long lager(Long[] arr){
        List<String> collect = Arrays.stream(arr).map(t -> t + "").collect(Collectors.toList());
        collect.sort(Main::compareT);
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = collect.size() - 1; i >= 0 ; i--) {
            stringBuilder.append(collect.get(i));
        }
        return Long.parseLong(stringBuilder.toString());
    }
    private static int compareT(String o1, String o2) {
        int length1 = o1.length();
        int length2 = o2.length();
        int i = 0,j = 0;
        while(length1 > i && length2 > j) {
            if(o1.charAt(i) == o2.charAt(j)) {
                i++;
                j++;
            } else {
                return o1.charAt(i) - o2.charAt(j);
            }
        }
        if(i != length1) {
            return o1.charAt(i) - o2.charAt(0);
        }
        if(j != length2) {
            return o2.charAt(j) - o1.charAt(0);
        }
        return 0;
    }
}
